@primary: #409eff;
@success: #67c23a;
@warning: #e6a23c;
@danger: #f56c6c;
@info: #909399;
@text-color: #303133;
@text-secondary: #606266;
@border-color: #dcdfe6;
@bg-color: #ffffff;
@shadow-base: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
@shadow-light: 0 0 6px 0 rgba(0, 0, 0, 0.12);

:root {
  --ng-popover-bg: @bg-color;
  --ng-popover-text-color: @text-color;
  --ng-popover-text-secondary: @text-secondary;
  --ng-popover-border-color: @border-color;
  --ng-popover-shadow: @shadow-base;
  --ng-popover-arrow-size: 8px;
}

// Popover 主容器
.ng-popover {
  position: absolute;
  background-color: var(--ng-popover-bg);
  border: 1px solid var(--ng-popover-border-color);
  border-radius: 4px;
  box-shadow: var(--ng-popover-shadow);
  padding: 0;
  max-width: 320px;
  z-index: 1060;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ng-popover-text-color);
  word-wrap: break-word;
  word-break: break-all;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;

  // 显示状态
  &.ng-popover-show {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
  }

  // 箭头
  .ng-popover-arrow {
    position: absolute;
    width: 0;
    height: 0;
    border-style: solid;
    border-color: transparent;

    &::before {
      content: '';
      position: absolute;
      width: 0;
      height: 0;
      border-style: solid;
      border-color: transparent;
    }
  }

  // 内容容器
  .ng-popover-inner {
    padding: 0;
  }

  // 标题
  .ng-popover-title {
    padding: 12px 16px;
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.5;
    color: var(--ng-popover-text-color);
    border-bottom: 1px solid var(--ng-popover-border-color);
    background-color: #fafafa;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
  }

  // 内容
  .ng-popover-content {
    padding: 12px 16px;
    color: var(--ng-popover-text-secondary);
    font-size: 14px;
    line-height: 1.6;
  }

  // 当没有标题时，内容圆角
  &:not(:has(.ng-popover-title)) .ng-popover-content {
    border-radius: 4px;
  }

  // Top placement
  &.ng-popover-top {
    margin-bottom: 10px;

    .ng-popover-arrow {
      bottom: -8px;
      left: 50%;
      margin-left: -8px;
      border-width: 8px 8px 0;
      border-top-color: var(--ng-popover-border-color);

      &::before {
        bottom: 1px;
        left: -8px;
        border-width: 8px 8px 0;
        border-top-color: var(--ng-popover-bg);
      }
    }
  }

  // Bottom placement
  &.ng-popover-bottom {
    margin-top: 10px;

    .ng-popover-arrow {
      top: -8px;
      left: 50%;
      margin-left: -8px;
      border-width: 0 8px 8px;
      border-bottom-color: var(--ng-popover-border-color);

      &::before {
        top: 1px;
        left: -8px;
        border-width: 0 8px 8px;
        border-bottom-color: var(--ng-popover-bg);
      }
    }
  }

  // Left placement
  &.ng-popover-left {
    margin-right: 10px;

    .ng-popover-arrow {
      right: -8px;
      top: 50%;
      margin-top: -8px;
      border-width: 8px 0 8px 8px;
      border-left-color: var(--ng-popover-border-color);

      &::before {
        right: 1px;
        top: -8px;
        border-width: 8px 0 8px 8px;
        border-left-color: var(--ng-popover-bg);
      }
    }
  }

  // Right placement
  &.ng-popover-right {
    margin-left: 10px;

    .ng-popover-arrow {
      left: -8px;
      top: 50%;
      margin-top: -8px;
      border-width: 8px 8px 8px 0;
      border-right-color: var(--ng-popover-border-color);

      &::before {
        left: 1px;
        top: -8px;
        border-width: 8px 8px 8px 0;
        border-right-color: var(--ng-popover-bg);
      }
    }
  }
}

// 不同主题色
.ng-popover-primary {
  .ng-popover-title {
    background-color: fade(@primary, 10%);
    color: @primary;
    border-bottom-color: fade(@primary, 20%);
  }
}

.ng-popover-success {
  .ng-popover-title {
    background-color: fade(@success, 10%);
    color: @success;
    border-bottom-color: fade(@success, 20%);
  }
}

.ng-popover-warning {
  .ng-popover-title {
    background-color: fade(@warning, 10%);
    color: @warning;
    border-bottom-color: fade(@warning, 20%);
  }
}

.ng-popover-danger {
  .ng-popover-title {
    background-color: fade(@danger, 10%);
    color: @danger;
    border-bottom-color: fade(@danger, 20%);
  }
}

// 暗色主题支持
@media (prefers-color-scheme: dark) {
  :root {
    --ng-popover-bg: #1f1f1f;
    --ng-popover-text-color: #e8e8e8;
    --ng-popover-text-secondary: #a8a8a8;
    --ng-popover-border-color: #3f3f3f;
    --ng-popover-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.4);
  }

  .ng-popover-title {
    background-color: #2a2a2a !important;
  }
}

// 动画
@keyframes popoverFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes popoverFadeOut {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.95);
  }
}

// 响应式
@media (max-width: 768px) {
  .ng-popover {
    max-width: calc(100vw - 32px);
    font-size: 13px;
  }

  .ng-popover-title {
    padding: 10px 14px;
    font-size: 13px;
  }

  .ng-popover-content {
    padding: 10px 14px;
    font-size: 13px;
  }
}
